<template>
  <div class="search" v-if="listdata">
    <div class="head">
      <div class="box">
        <div class="left">
          <input type="text" placeholder="请输入搜索关键字" v-model="text"  @keyup.enter="search" />
          <span>
           
          </span>
        </div>
        <div class="right">
          <div class="bts" @click="$router.go(-1)">取消</div>
        </div>
      </div>
    </div>
    <div class="content">
        <div class="top">
             <p>热门搜索</p>
        </div>
        <div class="nav">
            <span v-for="(item,index) in arr" :key="index" @click="add(item)">{{item}}</span>
        </div>
        <div class="middle">
     <router-link tag="div"  class="content" :to="'/item?id='+item.id" v-for="(item,index) in search()" :key='index' >
      <div class="left">
        <img
          :src="item.imgurl"
          alt=""
        />
      </div>
      <div class="right">
        <h5>{{item.name}}</h5>
        <p>{{item.Description}}</p>
        <span>&yen;{{item.price}}</span>
      </div>
     
    </router-link>
   </div>
    </div>
  </div>
</template>

<script>
export default {
    props:['listdata'],
    data() {
  
        return {
            arr: [
               '坚果 R2',
               '蓝牙耳机',
                'TNT',
               '移动电源',
                '坚果快充',
               '坚果R2保护套',
            ],
            text:null,
        };
    },
    methods: {
        add(i){
            this.text=i
        },
        search(){
             return this.listdata.filter(item=>item.name.includes(this.text))
        }
    },
};
</script>

<style lang="scss" scoped>
.search {
  .head {
    width: 100%;

    background-color: rgb(245, 245, 245);
    overflow: hidden;
    .box {
      width: 95%;
      display: flex;
      justify-content: space-between;

      margin: 10px auto;
      .left {
        height: 30px;
        width: 70%;
        padding: 0px 10px;
        border-radius: 20px;
        background-color: #fff;
        overflow: hidden;
        position: relative;
        span {
        position: absolute;
        left: 5px;
        top: 4px;
        z-index: 55;
          display: block;
          width: 23px;
          height: 23px;
          background-image: url(../assets/img/search.png);
          background-size: cover;
          background-repeat: no-repeat;

        }

        input {
          width: 80%;
          display: block;
          height: 30px;
          margin: 0px auto;
          outline: none;
          border: none;
          background-color: #fff;
          font-size: 12px;
          font-weight: 500;
          color: gray;
        }
      }
      .right {
        width: 30px;
        width: 20%;
        line-height: 30px;
        text-align: center;
        border: 1px solid rgb(210, 210, 210);
        border-radius: 5px;
        .bts {
          font-size: 14px;
          font-weight: 600;
          color:#626262;
        }
      }
    }
  }
  .content{
    width: 100%;
    margin-top: 30px;
    .top{
        width: 90%;
        margin: 0 auto;
    }
    .nav{
        width: 95%;
        margin: 5px auto;
        display: flex;
        flex-wrap: wrap;
        span{
            display: block;
            padding: 5px 15px;
            background-color: rgb(255, 231, 229);
            margin-right: 5px;
            margin-top: 5px;
            border-radius: 20px;
            border: 1px solid orange;
            color:rgb(195, 63, 51);
             font-weight: 600;
             font-size: 12px;
             line-height: 16px;
             text-align: center;
        }
    }
    .middle{
    margin-top: 50px;
    .content {
    width: 95%;
    height: 162px;
    
    background-color: #fff;
    display: flex;
    justify-content: flex-start;
    border-bottom: 1px solid #dfdede;
   
    .left {
      width: 48%;
      img {
        display: block;
        margin: 12% 0%;
        width: 126px;
        height: 126px;
      }
    }
    .right {
      width: 50%;
     display: flex;
     flex-direction: column;
     justify-content: center;
      
     
      h5{
      
        overflow: hidden;
        white-space: nowrap;
         text-overflow: ellipsis;
         color: #333;
         font-weight: 700;
         padding-bottom: 8px;
      }
      p{
         overflow: hidden;
        white-space: nowrap;
         text-overflow: ellipsis;
         font-size: 12px;
         color: #7f7f7f;
          padding-bottom: 30px;
      }
      span{
        color: #d44d44;
        font-weight: 700;
        font-size: 14px;
      }
    }
  }
  }
  }
}
</style>